package pers.liu.yibandemo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.liu.yibandemo.entity.Notification;
import pers.liu.yibandemo.mapper.NotificationMapper;

import java.time.Instant;
import java.util.List;

@Service
public class NotificationService extends ServiceImpl<NotificationMapper, Notification> {

    @Autowired
    private NotificationMapper notificationMapper;

    // 添加学校通知
    public void addNotification(Notification notification) {

        notificationMapper.insert(notification);
    }

    // 根据通知ID查询通知信息
    public Notification getNotificationById(Long notificationId) {
        return notificationMapper.selectById(notificationId);
    }

    // 查询所有学校通知
    public List<Notification> getAllNotifications() {
        QueryWrapper<Notification> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("noti_timestamp");
        return notificationMapper.selectList(wrapper);
    }

    public IPage<Notification> getNotificationsByPage(int pageNum,int pageSize){
        Page<Notification> page = new Page<>(pageNum, pageSize);
        Page<Notification> result = notificationMapper.selectPage(page, null);
        return result;
    }
    // 删除学校通知
    public void deleteNotification(Long notificationId) {

        notificationMapper.deleteById(notificationId);
    }

    // 更新学校通知
    public void updateNotification(Notification notification) {

        notificationMapper.updateById(notification);
    }
}
